package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.EmployeeDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

@Transactional
@Service(interfaceClass = EmployeeService.class)
public class EmployeeServiceImp implements EmployeeService{

    @Autowired
    private EmployeeDao employeeDao;

    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        PageHelper.startPage(currentPage,pageSize);
        Page page = employeeDao.findAll();
        return new PageResult(page.getTotal(),page.getResult());
    }

    @Override
    public void add(Employee employee) {
        employeeDao.add(employee);
    }
}
